#ifndef B2D_OBJECTMANAGER_H
#define B2D_OBJECTMANAGER_H

#include "IResourceManager.h"
#include "hashmap.h"

NS_B2D_BEGIN

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief	Global resource manager contains references to resource factories. Factories must be
/// 		registered for all resources types that are to be managed by it.
////////////////////////////////////////////////////////////////////////////////////////////////////
class B2D_API ResourceManager final
	: public IResourceManager
{
public:
	typedef hashmap<ObjectType, IResourceFactory*> FactoryMap;

private:
	FactoryMap mFactories;
	mutable std::mutex mFactoriesMutex;

public:
	// ::IResourceManager
	void registerFactory(IResourceFactory& factory);
	void unregisterFactory(const ObjectType& resourceType);
	ResourcePtr getResource(const ObjectType& type, const StringId& name) const;
	ResourcePtr getOrLoadResource(const ObjectType& type, const StringId& name);
	ResourcePtr createEmptyResource(const ObjectType& type, const StringId& name, bool addToCache = true);
	void addExistingResource(const ResourcePtr& res);
	void removeResource(const ObjectType& type, const StringId& name);
	void removeAll(void);
	void removeAllOfType(const ObjectType& t);
	void removeUnreferenced(void);
	void removeUnreferencedOfType(const ObjectType& t);
};


NS_B2D_END

#endif